<?php
//function __autoload($classname){require(SITE_DIR."/core/wizard/".$classname.".class.php");}
/**
 * VacancyWizard
 * 
 * @package yarland.ru
 * @author gogogo
 * @copyright 2009
 * @version $Id$
 * @access public
 */
class VacancyWizard extends Wizard
{
	var $table = "vacancy";
	var $pfx = "vacancy_";
	var $table_contact;
	var $table_spheres;
	var $table_occupations;
	var $cat;
	var $users;
	var $company;
	var $sphere_main_cat;
	var $occupation_main_cat;
	/**
	 * VacancyWizard::__construct()
	 * 
	 * @param mixed $db
	 * @param mixed $tablename
	 * @param string $pfx
	 * @param string $id
	 * @return void
	 */
	function __construct(object $db,string $tablename,string $pfx,string $id)
	{
		if(isset($db) and is_object($db)){$this->db = $db;}
		else{global $db;$this->db = $db;}
		if(strval($tablename) != ''){$this->table = mysql_real_escape_string($tablename);}
		if(strval($pfx) != ''){$this->pfx = mysql_real_escape_string($pfx);}
		if(strval($id) != ''){$this->pid = $id;}
		$this->table_contact = $this->pfx.'contacts';
		$this->table_spheres = $this->pfx.'sphere_tree';
		$this->table_occupations = $this->pfx.'occupation_tree';
		$this->cat = new CompanyCategoryWizard();
		$this->sphere_main_cat = $this->cat->byAlias('sphere','job');
		$this->occupation_main_cat = $this->cat->byAlias('job','job');
		$this->users = new UsersWizard;
		global $db_main;
		$this->users->init($db_main);
		$this->company = new CompanyWizard($this->db,'company');
	}
	function getVacancy($id = 0)
	{
		$item = $this->getItem($id);
		if($item != false)
		{
			//TODO: VacancyWizard::getVacancy->Item->spheres
			$vacancy_spheres = $this->db->fetch_list("SELECT category_id FROM $this->table_spheres WHERE $this->pid = '".$item['id']."'");
			$item['spheres'] = $this->cat->getCatArray($vacancy_spheres);
			//TODO: VacancyWizard::getVacancy->Item->occupations
			$vacancy_occupations = $this->db->fetch_list("SELECT category_id FROM $this->table_occupations WHERE $this->pid = '".$item['id']."'");
			$item['occupations'] = $this->cat->getCatArray($vacancy_occupations);
			//TODO: VacancyWizard::getVacancy->Item->author
			if(intval($item['company_id']) != 0)
			{
				$author = $this->company->companyLink(intval($item['company_id']));
				$item['author'] = ($author != false?$author:'');
			}
			elseif(intval($item['user_id']) != 0)
			{
				$author = $this->users->user_get_data(intval($item['user_id']));
				$item['author'] = $author['print_login'];
			}
			//TODO: VacancyWizard::getVacancy->Item->city
			$vacancy_city = $this->db->fetch_one("SELECT * FROM cities WHERE id = '".$item['city_id']."'");
			$item['city'] = $vacancy_city['title'];
			return $item;
		}
		else return false;
	}
}
?>